/*
 *    Copyright (c) 2018-2025, fanxl All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: fanxl (xunlian_fan001@126.com)
 */

package com.taiji.dicom4cloud.smart.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.taiji.dicom4cloud.common.core.utils.CommonUtils;
import com.taiji.dicom4cloud.common.core.utils.R;
import com.taiji.dicom4cloud.common.log.annotation.SnowLog;
import com.taiji.dicom4cloud.smart.model.entity.Photo;
import com.taiji.dicom4cloud.smart.service.PhotoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 
 *
 * @author fanxl
 * @date 2021-07-06 10:47:06
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/photo" )
@Api(value = "photo", tags = "管理")
public class PhotoController {

    private final PhotoService photoService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param photo 
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R getPhotoPage(Page page, Photo photo) {
        return R.ok(photoService.page(page, Wrappers.query(photo)));
    }


    /**
     * 通过id查询
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(photoService.getById(id));
    }


    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/photoId/{photoId}" )
    public R getById(@PathVariable("photoId" ) String photoId) {
        return R.ok(photoService.getPhotoListById(photoId));
    }

    /**
     * 新增
     * @param photo 
     * @return R
     */
    @ApiOperation(value = "新增", notes = "新增")
    @SnowLog("新增" )
    @PostMapping
    public R save(@RequestBody Photo photo) {
        String photoId = CommonUtils.getUUID();
        photo.setPhotoId(photoId);
        photoService.save(photo);
        return R.ok(photoId);
    }

    @ApiOperation(value = "新增", notes = "新增")
    @SnowLog("批量新增" )
    @PostMapping("/batch-save")
    public R batchSave(@RequestBody List<Photo> photos) {
        return R.ok(photoService.batchSavePhotos(photos));
    }

    /**
     * 修改
     * @param photo 
     * @return R
     */
    @ApiOperation(value = "修改", notes = "修改")
    @SnowLog("修改" )
    @PutMapping
    public R updateById(@RequestBody Photo photo) {
        return R.ok(photoService.updateById(photo));
    }

    /**
     * 通过id删除
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除", notes = "通过id删除")
    @SnowLog("通过id删除" )
    @DeleteMapping("/{id}" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(photoService.removeById(id));
    }

}
